import {
	service
} from "../http";


export const mock = {
	/**
	 * @param {Object} params.
	 * @param {String} params.searchFiled 检索字段 题名检索title  责任人检索author  isbn检索isbn 元数据控制号检索recordId    条码号检索barcode 关键字keyWord
	 * @param {String} params.searchWord 检索内容 
	 * @param {Number} params.page 当前页 默认第一页
	 * @param {Number} params.rows 每页显示数 默认30条，最大50条
	 * @param {String} params.groupCode 机构代码
	 * @param {Array} params.locationId 馆藏地Id
	 * @param {String} params.sortClause 排序 desc 降序，asc 升序
	 * @param {String} params.sortField 排序字段 创建时间create_date 相关度relevance 出版时间issued_sort  题名title_sort 责任者author_sort 索书号call_no_sort  分类号class_no_sort_s 出版社publisher_sort 标准号isbn_sort_s 元数据控制号record_id
	 */
	searchBook: (params) => service.post('/open/fu/bookInfo/searchBook', params),



	/**
	 * 查询图书
	 * @param {Object} params.
	 * @param {String} params.bookBarCode 图书条码
	 * @param {String} params.bookLibCode 图书所在馆
	 */
	physicalitem: (params) => service.post('/fu/loa/physicalitem/get', params),


}

export const getHotLoanApi = () => {
	return new Promise((resolve, reject) => {
		uni.request({
			method: "POST",
			header: {
				groupCode: 200406
			},
			url: "https://mfindjxkeda.libsp.cn/find/index/getHotLoan",
			data: {
				"disCode": null,
				"page": 1,
				"rows": 10,
				"indexFlag": 1,
				"statRange": 365
			},
			success: ({
				data
			}) => {
				if (data.errCode == 200) {
					resolve(data)
				} else {
					reject()
				}
			}
		})

	})
}
let emptyIndex = 1
let emptyIndexMax = 4
export const getDuxiuImageUrl = (title, isbn, recordId) => {
	return new Promise((resolve, reject) => {
		uni.request({
			method: "GET",
			url: "https://findjxkeda.libsp.cn/find/book/getDuxiuImageUrl",
			data: {
				title,
				isbn,
				recordId
			},
			success: ({
				data
			}) => {
				if (data.errCode == 200) {
					let cover = data.data || require(`@/static/empty/index0${emptyIndex}.png`)
					emptyIndex = emptyIndex === emptyIndexMax ? 1 : emptyIndex + 1
					resolve({
						cover,
						coverEmpty: !data.data
					})
				} else {
					reject()
				}
			}
		})

	})
}

export const getImageUrl = (list) => {
	return new Promise((resolve, reject) => {
		let asyncQueue = []
		list.forEach((item, index) => {
			const asyncItem = getDuxiuImageUrl(item.title, item.isbn, item.recordId)
				.then((data) => {
					return Object.assign(item, data)
				})
			asyncQueue.push(asyncItem)
		})
		Promise.all(asyncQueue).then((list) => {
			resolve(list)
		})
	})

}

export const sortField = [{
		name: "创建时间",
		key: 'create_date '
	},
	{
		name: "相关度",
		key: 'relevance '
	},
	{
		name: "出版时间",
		key: 'issued_sort  '
	},
	{
		name: "题名",
		key: 'title_sort '
	},
	{
		name: "责任者",
		key: 'author_sort '
	},
	{
		name: "索书号",
		key: 'call_no_sort  '
	},
	{
		name: "分类号",
		key: 'class_no_sort_s '
	},
	{
		name: "出版社",
		key: 'publisher_sort '
	},
	{
		name: "标准号",
		key: 'isbn_sort_s '
	},
	{
		name: "元数据控制号",
		key: 'record_id'
	},
]

export const SearchFiledDic = [{
		name: "题名",
		key: "title"
	},
	{
		name: "责任人",
		key: "author"
	},
	{
		name: "isbn",
		key: "isbn"
	},
	{
		name: "元数据控制号",
		key: "recordId"
	},
	{
		name: "条码号",
		key: "barcode"
	},
	{
		name: "关键字",
		key: "keyWord"
	},
]
export const ProcessType = {
	"111": "验收",
	"211": "在编",
	"311": "待分配",
	"312": "送修",
	"313": "丢失",
	"314": "赠送",
	"315": "交换",
	"316": "报废",
	"317": "调拨中",
	"318": "待清点",
	"411": "在架",
	"412": "借出",
	"413": "上预约书架",
	"414": "物流中",
	"415": "预约借出",
	"416": "委托借出",
	"417": "物流借出",
	"418": "预约中",
	"419": "签收",
	"420": "交接",
	"421": "单刊典藏",
	"422": "下架",
	"423": "装订中",
	"424": "已装订",
}